package yartiss.engine.simulation.system;

import yartiss.engine.simulation.IEnergyConsumptionProfile;

/**
 * @author Frederic Fauberteau & Manar Qamhieh
 */

public abstract class PeriodicTask extends AbstractTask {
	public PeriodicTask(long firstRelease, long wcet, long wcee, long period, long deadline, int priority, IEnergyConsumptionProfile p) {
		super(firstRelease, wcet, wcee, period, deadline, priority,  p);
	}

	/**
	 * Calculates the utilization of the task, where U = WCET/T
	 * 
	 * @return task's utilization
	 */
	public double getUtilization() {
		return (double) getWcet() / getPeriod();
	}

	/**
	 * Calculates the density of the task, where density = WCET/(min(P,d))
	 * 
	 * @return task's density
	 */
	public double getDensity() {
		return (double) getWcet() / Math.min(getDeadline(), getPeriod());
	}

	/**
	 * Checks if the task is an implicit-deadline task, in which the deadline
	 * equals to its period
	 * 
	 * @return true if it is an implicit-deadline task, false otherwise
	 */
	public boolean isImplicitDeadline() {
		if (getDeadline() == getPeriod()) {
			return true;
		}
		return false;
	}

	/**
	 * Checks if the task is a constrained-deadline task, in which the deadline
	 * less or equals to its period
	 * 
	 * @return true if it is a constrained-deadline task, false otherwise
	 */
	public boolean isConstrainedDeadline() {
		if (getDeadline() <= getPeriod()) {
			return true;
		}
		return false;
	}

	/**
	 * Checks if the task is an arbitrary-deadline task
	 * 
	 * @return true if it is an arbitrary-deadline task, false otherwise
	 */
	public boolean isArbitraryDeadline() {
		if (getDeadline() > getPeriod()) {
			return true;
		}
		return false;
	}

}
